<template>
  <div class="login-page">
<!--    <div class="login-title">北理数据中控大屏</div>-->
    <div class="login-bar"></div>
    <div class="login-form">
      <div class="title">登录</div>
      <el-form :model="loginForm" :rules="loginRules" ref="loginForm" label-width="0">
        <el-form-item prop="account">
          <el-input placeholder="请输入用户名" v-model="loginForm.account"></el-input>
        </el-form-item>
        <el-form-item prop="password">
          <el-input type="password" placeholder="请输入密码" v-model="loginForm.password"></el-input>
        </el-form-item>
        <el-form-item>
          <el-button class="login-submit" type="primary" @click="submitForm('loginForm')">登录</el-button>
        </el-form-item>
      </el-form>
    </div>
  </div>
</template>
<script>
import portal from '@/api/portal'
export default {
  name: 'LoginPage',
  data () {
    return {
      loginForm: {
        account: '',
        password: ''
      },
      loginRules: {
        account: [
          { required: true, message: '请输入用户名!', trigger: 'blur' }
        ],
        password: [
          { required: true, message: '请输入密码!', trigger: 'blur' }
        ]
      },
      passwordType: 'password'
    }
  },
  created () {
  },
  mounted () {
  },
  methods: {
    submitForm (formName) {
      // this.$router.replace('/home')
      this.$refs[formName].validate((valid) => {
        if (valid) {
          this.login()
        }
      })
    },
    async login () {
      const res = await portal.login(this.loginForm)
      if (res.data && res.data.api_token) {
        this.$store.commit('SET_TOKEN', res.data.api_token)
        this.$router.replace('/main')
        this.$message.success('登录成功')
      }
    }
  }
}
</script>

<style scoped lang="scss">
.login-page{
  position: absolute;
  width: 100vw;
  min-height: 100vh;
  background-image: url("../../assets/images/login.png");
  background-size: cover;
  z-index: 1;
  .login-title {
    font-size: 40px;
    color: #fff;
    font-weight: 800;
    text-align: center;
    margin-top: 20px;
  }
  .login-bar {
    position: absolute;
    width: 100%;
    height: 200px;
    left: 0;
    top: calc(50% - 80px);
    background-color: #fff;
    opacity: 0.3;
    z-index: 2;
  }
  .login-form {
    position: absolute;
    width: 300px;
    height: 280px;
    z-index: 3;
    left: calc(50% - 150px);
    top: calc(50% - 120px);
    background-color: #fff;
    margin: auto;
    opacity: 1;
    border-radius: 10px;
    .el-form {
      position: relative;
      padding: 0 10px;
      .el-form-item {
        margin: 0 0 20px 0;
      }
    }
    .title {
      color: #265A35;
      font-size: 20px;
      text-align: center;
      margin: 10px;
      line-height: 50px;
      height: 50px;
    }
    .login-submit {
      color: #fff;
      background-color: #265A35;
      width: 100%;
      height: 40px;
      padding: 0;
      line-height: 40px;
    }
  }
}
</style>
